<template>
	<div>
		<Chart :cdata="cdata" />
	</div>
</template>

<script>
	import Chart from './chart.vue'
	export default {
		data() {
			return {
				cdata: {
					xData: [],
					yData: []
				}
			}
		},
		components: {
			Chart,
		},
		mounted() {
			this.getAir()
		},

		methods: {
			getAir() {
				this.$http.get("/view/quality/list").then((res) => {
					console.log("=======>quality", res.data.rows)
					let qualitys = res.data.rows
					let datax = []
					let datay = []
					// 循环遍历数组，取出数据，转成和data一样的格式
					for (var i = 0; i < qualitys.length; i++) {
						datax.push(qualitys[i].airQuality)
						datay.push(qualitys[i].airQualityCount)
					}
					this.cdata.xData = datax
					this.cdata.yData = datay
					// this.cdata.serData = data
				}).catch((err) => {
					console.log(err)
					alert('请求失败！请检查后端接口！！！！')
				})
			}
		}
	
	};
</script>

<style lang="scss" scoped>
</style>
